Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support gRPC communication between primary and secondary mantle controllers #32

Merged
merged 3 commits into from
Aug 30, 2024

Conversation

ushitora-anqou
Copy link
Contributor

No description provided.

@ushitora-anqou ushitora-anqou force-pushed the support-grpc-comm branch 7 times, most recently from 8575c8b to 6cbd772 Compare August 29, 2024 08:11
@ushitora-anqou ushitora-anqou marked this pull request as ready for review August 29, 2024 08:47
Copy link
Contributor

@satoru-takeuchi satoru-takeuchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only reviewed the first commit so far. Please reflect my comments during my remaining reviews.

Makefile Outdated
@@ -52,7 +69,7 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
cat config/rbac/role.yaml | yq '.metadata.name = "mantle-controller"' > charts/mantle-cluster-wide/templates/clusterrole.yaml

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
generate: $(PROTOBUF_GEN) controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
generate: $(PROTOBUF_GEN) controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
generate: $(PROTOBUF_GEN) controller-gen ## Generate boilerplate code.

Now generate target generates not only code for CR handling but also gRPC code.

// nothing to do
case RolePrimary:
if mantleServiceEndpoint == "" {
return errors.New("--mantle-service-endpoint should be specified if --role is 'primary'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return errors.New("--mantle-service-endpoint should be specified if --role is 'primary'")
return errors.New("--mantle-service-endpoint must be specified if --role is 'primary'")

}
case RoleSecondary:
if mantleServiceEndpoint == "" {
return errors.New("--mantle-service-endpoint should be specified if --role is 'secondary'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return errors.New("--mantle-service-endpoint should be specified if --role is 'secondary'")
return errors.New("--mantle-service-endpoint must be specified if --role is 'secondary'")

Comment on lines 163 to 167
managedCephClusterID := os.Getenv("POD_NAMESPACE")
if managedCephClusterID == "" {
setupLog.Error(errors.New("POD_NAMESPACE is empty"), "POD_NAMESPACE is empty")
return errors.New("POD_NAMESPACE is empty")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is not necessary since managedCephClusterId will be initialized in setupReconcilers.


l, err := net.Listen("tcp", mantleServiceEndpoint)
if err != nil {
return fmt.Errorf("failed to listen: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to listen: %w", err)
return fmt.Errorf("failed to listen %s: %w", mantleServiceEndpoint, err)

return err
}

var wg sync.WaitGroup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var wg sync.WaitGroup
var wg sync.WaitGroup
wg.Add(1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my mistake, and I should call wg.Add every time go is called. I'll fix my code so.

}()

go func() {
defer wg.Done()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is unnecessary since wg.Done() will be called by L215. If this line exists, wg.Done() will be called twice and this will result in panic.

Copy link
Contributor Author

@ushitora-anqou ushitora-anqou Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my mistake, and I should call wg.Add every time go is called. I'll fix my code so.


go func() {
defer wg.Done()
_ = serv.Serve(l)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking error and logging is better.

@@ -20,13 +20,15 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

mantlev1 "github.com/cybozu-go/mantle/api/v1"
"github.com/cybozu-go/mantle/pkg/controller/proto"
)

// MantleBackupReconciler reconciles a MantleBackup object
type MantleBackupReconciler struct {
client.Client
Scheme *runtime.Scheme
managedCephClusterID string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding role field? Although we can distinguish whether the role is primary by primarySettings, checking rolle == RolePrimary is more straightforward.

<-ctx.Done()
serv.GracefulStop()
}()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also call setupReconciler() for the secondary mantle and do nothing in Reconcile() if the rolle is secondary?

@ushitora-anqou ushitora-anqou force-pushed the support-grpc-comm branch 2 times, most recently from ffe0e5a to 5e2a32a Compare August 30, 2024 02:49
@ushitora-anqou
Copy link
Contributor Author

ushitora-anqou commented Aug 30, 2024

I've fixed my code to resolve your points.

…ollers

This commit allows a mantle-controller to serve as one of standalone,
primary, or secondary mode. This commit doesn't have any e2e test's
update and it will land on in the following commits.

Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
All of the e2e tests we currently have are written for a single
Kubernetes cluster. This commit moves them into a `singlek8s` package.

Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
@satoru-takeuchi satoru-takeuchi merged commit 6d00b20 into main Aug 30, 2024
3 checks passed
@satoru-takeuchi satoru-takeuchi deleted the support-grpc-comm branch August 30, 2024 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants